/**
 * @file	uart_process.c
 * @author	chipsea
 * @brief	
 * @version	0.1
 * @date	2020-11-30
 * @copyright Copyright (c) 2020, CHIPSEA Co., Ltd.
 * @note
 */

/*********************************************************************
 * INCLUDES
 */
#include "sdk_config.h"
#include "uart_process.h"
#include "log.h"
#include "gap.h"
#include "OSAL.h"
#include "flash.h"
#include "multi.h"
#include "pwrmgr.h"
#include "user_data.h"
#include "multi_role.h"
#include "halPeripheral.h"
#include "rf_phy_driver.h"
#include "gapgattserver.h"


#define FM_VERSION  "V130"

const uint32_t baud_table[5] = {115200, 57600, 38400, 19200, 9600};
//100ms,200ms,300,ms,400ms,500ms,1000ms,2000ms,3000ms,4000ms
const uint16_t advin_table[9] = {160, 320, 480, 640, 800, 1600, 3200, 4800, 6400};
//50ms,100ms,200,ms,300ms,500ms,1000ms,1500ms
const uint16_t connin_table[7] = {40, 80, 160, 240, 400, 800, 1200};

#if (CFG_DCDC_ENABLE == 0)
//-5db,-3db,0db,3db,5db
const uint8_t power_table[5] = {0x06, 0x0a, 0x0d, 0x15, 0x1d};
#else
//-5db,-2db,0db,5db,5db
const uint8_t power_table[5] = {0x06, 0x0a, 0x0d, 0x1d, 0x1d};
#endif

uint8_t adv_en = true;

void reply_ok(void)
{
    uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'O';
    uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'K';
    uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
    uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
}

uint8_t uart_analysis(uint8_t *pdata)
{
    uint8_t i = 0;
    uint8_t ret = 0;
    uint32_t temp = 0;
    uint8_t advData[B_MAX_ADV_LEN];
    
    if( osal_memcmp(pdata, "\r\n", 2) )
    {
        LOG("AT\r\n");
        reply_ok();
        ret = 4;
    }
    
    if( osal_memcmp(pdata, "+RST\r\n", 6) )
    {
        LOG("AT+RST\r\n");
        reply_ok();
        if(masterPeerConnectionInfo[0].ConnectionState)
        {
            GAPMultiRole_TerminateConnection(masterPeerConnectionInfo[0].ConnectionHandle);
        }
        status_change = STATUS_RESET;
        ret = 8;
    }
    
    if( osal_memcmp(pdata, "+BAUD", 5) )
    {
        LOG("AT+BAUD\r\n");
        if( (pdata[5] == ':') && \
            (pdata[6] == '<') && (pdata[8] == '>') && \
            (pdata[9] == '\r') && (pdata[10] == '\n') && \
            (pdata[7] >= '0') && (pdata[7] <= '4') )
        {
            status_change = STATUS_BAUD;
            reply_ok();
            user_data.baud = pdata[7]-'0';
            user_data_save();
            ret = 13;
        }
        else if( (pdata[5] == '\r') && (pdata[6] == '\n') )
        {
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'B';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'A';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'U';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'D';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = user_data.baud+'0';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 9;
        }
    }
    
    if( osal_memcmp(pdata, "+DISC\r\n", 7) )
    {
        LOG("AT+DISC\r\n");
        reply_ok();
        if(masterPeerConnectionInfo[0].ConnectionState)
        {
            GAPMultiRole_TerminateConnection(masterPeerConnectionInfo[0].ConnectionHandle);
        }
        ret = 9;
    }
    
    if( osal_memcmp(pdata, "+ADVEN", 6) )
    {
        LOG("AT+ADVEN\r\n");
        if( (pdata[6] == ':') && \
            (pdata[7] == '<') && (pdata[9] == '>') && \
            (pdata[10] == '\r') && (pdata[11] == '\n') && \
            (pdata[8] >= '0') && (pdata[8] <= '1') )
        {
            reply_ok();
            i = pdata[8] - '0';
            adv_en = i;
            if(!masterPeerConnectionInfo[0].ConnectionState)
            {
                GAPMultiRole_SetParameter( GAPROLE_ADVERT_ENABLED, 1, &i, NULL);
            }
            ret = 14;
        }
        else if( (pdata[6] == '\r') && (pdata[7] == '\n') )
        {
            GAPMultiRole_GetParameter(GAPROLE_ADVERT_ENABLED, &i, masterPeerConnectionInfo[0].ConnectionHandle);
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'A';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'D';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'V';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'E';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'N';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = i+'0';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 10;
        }
    }
    
    if( osal_memcmp(pdata, "+ADVIN", 6) )
    {
        LOG("AT+ADVIN\r\n");
        if( (pdata[6] == ':') && \
            (pdata[7] == '<') && (pdata[9] == '>') && \
            (pdata[10] == '\r') && (pdata[11] == '\n') && \
            (pdata[8] >= '0') && (pdata[8] <= '8') )
        {
            reply_ok();
            user_data.advin = pdata[8] - '0';
            if(!masterPeerConnectionInfo[0].ConnectionState)
            {
                i = false;
                GAPMultiRole_SetParameter(GAPROLE_ADVERT_ENABLED, 1, &i, NULL);
                ble_task_set(USER_TASK_START, START_ADVERT_EVT, 10);
            }
            GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MIN, advin_table[user_data.advin]);
            GAP_SetParamValue(TGAP_LIM_DISC_ADV_INT_MAX, advin_table[user_data.advin]);
            GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MIN, advin_table[user_data.advin]);
            GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advin_table[user_data.advin]);
            user_data_save();
            ret = 14;
        }
        else if( (pdata[6] == '\r') && (pdata[7] == '\n') )
        {
//            temp = GAP_GetParamValue(TGAP_LIM_DISC_ADV_INT_MIN);
//            if(temp > advin_table[4])
//            {
//                i = temp/advin_table[5]-1 + '5';
//            }
//            else
//            {
//                i = temp/advin_table[0]-1 + '0';
//            }
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'A';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'D';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'V';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'I';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'N';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = user_data.advin+'0';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 10;
        }
    }
    
    if( osal_memcmp(pdata, "+CONNIN", 7) )
    {
        LOG("AT+CONNIN\r\n");
        if( (pdata[7] == ':') && \
            (pdata[8] == '<') && (pdata[10] == '>') && \
            (pdata[11] == '\r') && (pdata[12] == '\n') && \
            (pdata[9] >= '0') && (pdata[9] <= '6') )
        {
            reply_ok();
            user_data.connin = pdata[9] - '0';
            GAPMultiRole_SetParameter(GAPROLE_MIN_CONN_INTERVAL, 2, (uint8_t *)&connin_table[user_data.connin], NULL);
            GAPMultiRole_SetParameter(GAPROLE_MAX_CONN_INTERVAL, 2, (uint8_t *)&connin_table[user_data.connin], NULL);
            user_data_save();
            ret = 15;
        }
        else if( (pdata[7] == '\r') && (pdata[8] == '\n') )
        {
//            GAPRole_GetParameter(GAPROLE_MIN_CONN_INTERVAL, &temp);
//            if(temp <= connin_table[0])
//            {
//                i = '0';
//            }
//            else if(temp <= connin_table[3])
//            {
//                i = temp/advin_table[1] + '0';
//            }
//            else
//            {
//                i = temp/advin_table[4]+3 + '0';
//            }
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'C';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'O';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'N';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'N';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'I';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'N';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = user_data.connin+'0';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 11;
        }
    }
    
    if( osal_memcmp(pdata, "+POWER", 6) )
    {
        LOG("AT+POWER\r\n");
        if( (pdata[6] == ':') && \
            (pdata[7] == '<') && (pdata[9] == '>') && \
            (pdata[10] == '\r') && (pdata[11] == '\n') && \
            (pdata[8] >= '0') && (pdata[8] <= '4') )
        {
            reply_ok();
            user_data.power = pdata[8]-'0';
            rf_phy_set_txPower(power_table[user_data.power]);
            user_data_save();
            ret = 14;
        }
        else if( (pdata[6] == '\r') && (pdata[7] == '\n') )
        {
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'P';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'O';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'W';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'E';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'R';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = user_data.power+'0';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 10;
        }
    }
    
    if( osal_memcmp(pdata, "+NAME", 5) )
    {
        LOG("AT+NAME\r\n");
        if( (pdata[5] == ':') && (pdata[6] == '<') )
        {
            for(i=7; i<33; i++)
            {
                if( (pdata[i] == '>') && (pdata[i+1] == '\r') && (pdata[i+2] == '\n') )
                {
                    break;
                }
            }
            LOG("NAME:%d\r\n", i);
            if(i >= 33)
            {
                ret = 0xFF;
            }
            else
            {
                reply_ok();
                temp = i - 7;
                //set scan_rsp information
                i = 0;
                osal_memset(simpleBLEDeviceName, 0, sizeof(simpleBLEDeviceName));
                osal_memcpy(simpleBLEDeviceName, pdata+7, temp);
                osal_memset(user_data.name, 0, sizeof(user_data.name));
                osal_memcpy(user_data.name, pdata+7, temp);
                osal_memcpy(advertData+14, simpleBLEDeviceName, temp);
                GAPMultiRole_SetParameter( GAPROLE_ADVERT_DATA, 26, advertData, 0);
                GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, simpleBLEDeviceName );
                user_data_save();
                ret = temp+12;
            }
        }
        else if( (pdata[5] == '\r') && (pdata[6] == '\n') )
        {
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'N';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'A';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'M';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'E';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            for(i=0; i<osal_strlen((char *)simpleBLEDeviceName); i++)
            {
                uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = simpleBLEDeviceName[i];
            }
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 9;
        }
    }
    
    if( osal_memcmp(pdata, "+MAC", 4) )
    {
        uint8_t mac[B_ADDR_LEN] = {0};
        
        LOG("AT+MAC\r\n");
        if( (pdata[4] == ':') && (pdata[5] == '<') )
        {
            for(i=6; i<19; i++)
            {
                if( (pdata[i] == '>') && (pdata[i+1] == '\r') && (pdata[i+2] == '\n') )
                {
                    break;
                }
            }
            if(i >= 19)
            {
                ret = 0xFF;
            }
            else
            {
                for(i=0; i<12; i++)
                {
                    if( (pdata[6+i] >= '0') && (pdata[6+i] <= '9') )
                    {
                        mac[5-(i>>1)] |= (pdata[6+i]-'0')<<((i%2)?4:0);
                    }
                    else if( (pdata[6+i] >= 'A') && (pdata[6+i] <= 'F') )
                    {
                        mac[5-(i>>1)] |= (pdata[6+i]-'A'+0x0A)<<((i%2)?4:0);
                    }
                    else if( (pdata[6+i] >= 'a') && (pdata[6+i] <= 'f') )
                    {
                        mac[5-(i>>1)] |= (pdata[6+i]-'a'+0x0A)<<((i%2)?4:0);
                    }
                    else
                    {
                        break;
                    }
                }
                if(i >= B_ADDR_LEN)
                {
                    reply_ok();
                    i = false;
                    if(!masterPeerConnectionInfo[0].ConnectionState)
                    {
                        GAPMultiRole_SetParameter(GAPROLE_ADVERT_ENABLED, 1, &i, NULL);
                        ble_task_set(USER_TASK_START, START_ADVERT_EVT, 10);
                    }
                    GAPMultiRole_SetParameter(GAPROLE_BD_ADDR, B_ADDR_LEN, mac, NULL);
                    //set adv_data information
                    osal_memcpy(advData, advertData, sizeof(advertData));
                    for(uint8_t i=0; i<B_ADDR_LEN; i++)
                    {
                        advData[i+5] = mac[5-i];
                    }
                    GAPMultiRole_SetParameter(GAPROLE_ADVERT_DATA, sizeof(advertData), advData, NULL);
                    osal_memcpy(user_data.mac, mac, B_ADDR_LEN);
                    user_data_save();
                    ret = 23;
                }
            }
        }
        else if( (pdata[4] == '\r') && (pdata[5] == '\n') )
        {
            const char hex[] = "0123456789ABCDEF";
            
            LOG("read MAC\r\n");
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'M';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'A';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'C';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '<';
            
            GAPMultiRole_GetParameter(GAPROLE_BD_ADDR, mac, NULL);
            for(i=0; i<B_ADDR_LEN; i++)
            {
                uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = hex[(mac[5-i]>>4)&0x0F];
                uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = hex[mac[5-i]&0x0F];
            }
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '>';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
            uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
            ret = 8;
        }
    }
    
    if( osal_memcmp(pdata, "+VER\r\n", 6) )
    {
        LOG("AT+VER\r\n");
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'V';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'E';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'R';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = FM_VERSION[0];
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = FM_VERSION[1];
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = FM_VERSION[2];
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = FM_VERSION[3];
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
        ret = 8;
    }
    
    if( osal_memcmp(pdata, "+GETSTAT\r\n", 10) )
    {
        LOG("AT+GETSTAT\r\n");
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'G';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'E';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'T';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'S';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'T';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'A';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = 'T';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = ':';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = masterPeerConnectionInfo[0].ConnectionState+'0';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\r';
        uart_tx_data.data[(uart_tx_data.wr++)&(UART_BUF_SIZE-1)] = '\n';
        ret = 12;
    }
    
    if( osal_memcmp(pdata, "+RESTORE\r\n", 10) )
    {
        status_change = STATUS_RESTORE;
        LOG("AT+RESTORE\r\n");
        reply_ok();
        HalFlashErase(BAUD_FLASH_ADDR1>>12);
        HalFlashErase(BAUD_FLASH_ADDR2>>12);
        ret = 12;
    }
    
    if( osal_memcmp(pdata, "+SLEEP\r\n", 8) )
    {
        status_change = STATUS_POWEROFF;
        LOG("AT+SLEEP\r\n");
        reply_ok();
        ret = 10;
    }
    
    if( osal_memcmp(pdata, "+OTA\r\n", 6) )
    {
        status_change = STATUS_OTA;
        LOG("AT+OTA\r\n");
        reply_ok();
        ret = 8;
    }
    
    if(ret)
    {
        osal_stop_timerEx(Hal_TaskID, USR_UART_SEND_DATA);
        osal_set_event(Hal_TaskID, USR_UART_SEND_DATA);
    }
    return ret;
}

/*********************************************************************
*********************************************************************/
